package org.filecollector.filecontroller.operationresults;

import lombok.NonNull;

import java.net.URI;
import java.util.Optional;

public record OperationResponse(
        @NonNull OperationResult result,
        @NonNull Optional<char[]> buffer,
        @NonNull Optional<URI> retURI,
        boolean needToCallTroublesHunter
) {
    public static OperationResponse constructWrongId() {
        return new OperationResponse(
                OperationResult.WRONG_ID,
                Optional.empty(),
                Optional.empty(),
                false
        );
    }

    public static OperationResponse constructSuccess() {
        return new OperationResponse(
                OperationResult.OK,
                Optional.empty(),
                Optional.empty(),
                false
        );
    }

    public static OperationResponse constructNotSuchId() {
        return new OperationResponse(
                OperationResult.NOT_SUCH_ID,
                Optional.empty(),
                Optional.empty(),
                true
        );
    }

    public static OperationResponse constructSuccessBuffered(char[] buffer) {
        return new OperationResponse(
                OperationResult.OK,
                Optional.of(buffer),
                Optional.empty(),
                false
        );
    }

    public static OperationResponse constructExceptionThrew() {
        return new OperationResponse(
                OperationResult.EXCEPTION_THREW,
                Optional.empty(),
                Optional.empty(),
                true
        );
    }

    public static OperationResponse constructSomethingGoesWrong() {
        return new OperationResponse(
                OperationResult.SOMETHING_WRONG,
                Optional.empty(),
                Optional.empty(),
                true
        );
    }

    public static OperationResponse constructFileAlreadyRemoved() {
        return new OperationResponse(
                OperationResult.ALREADY_DONE,
                Optional.empty(),
                Optional.empty(),
                false
        );
    }

    public static OperationResponse constructCatalogueAlreadyTracking() {
        return new OperationResponse(
                OperationResult.ALREADY_DONE,
                Optional.empty(),
                Optional.empty(),
                false
        );
    }

    public static OperationResponse constructWrongCatalogueName() {
        return new OperationResponse(
                OperationResult.INTERSECTED_NAME,
                Optional.empty(),
                Optional.empty(),
                false
        );
    }

    public boolean hasBuffer() {
        return buffer.isPresent();
    }

    public boolean hasURL() {
        return retURI.isPresent();
    }

    public char[] readBuffer() {
        return buffer.orElseThrow();
    }

    public URI readURL() {
        return retURI.orElseThrow();
    }
}
